<?php

namespace App\Http\Controllers\YApi;

// use Illuminate\Http\Request;
use Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use Session;
use Redirect;
use Illuminate\Pagination\LengthAwarePaginator;

use App\Models\Book;
use App\Models\Shudan;
use App\Models\UsersReg;
use App\Models\BooksReview; // 长评
use App\Models\BooksComments; // 短评

class ShupinglistController extends Controller
{

    public function shupinglist()
    {
        //全部长书评列表
        $booksreviews = BooksReview::orderBy('id', 'desc')->paginate(15);
        
        foreach($booksreviews as $booksreview)
        {
            //为了得到图书的信息
            $booksreview['books'] = Book::find($booksreview->book_id);
        }

        foreach ($booksreviews as $reviewuser) {
            //得到发布长评论的会员资料
            $reviewuser['users'] = UsersReg::find($reviewuser->uid);
        }
        
        return $booksreviews;     
    }

    public function usershupinglist($uid)
    {
        //会员的长书评列表
        $booksreviews = BooksReview::where('uid', $uid)->orderBy('id', 'desc')->paginate(15);
        
        foreach($booksreviews as $booksreview)
        {
            //为了得到图书的信息
            $booksreview['books'] = Book::find($booksreview->book_id);
        }

        foreach ($booksreviews as $reviewuser) {
            //得到发布长评论的会员资料
            $reviewuser['users'] = UsersReg::find($reviewuser->uid);
        }
        
        return $booksreviews;     
    }

    public function bookduanshupinglist($bookid)
    {
        // 对应的书籍的短书评列表
        $bookduanshupinglists = BooksComments::where('book_id', $bookid)->orderBy('add_time', 'desc')->paginate(10);
        foreach ($bookduanshupinglists as $bookduanshupinglist) {
            //得到发布短评论的会员资料
            $bookduanshupinglist['users'] = UsersReg::find($bookduanshupinglist->uid);
        }
        return $bookduanshupinglists;
    }

    public function bookchangshupinglist($bookid)
    {
        // 对应的书籍的长书评列表
        $bookchangshupinglists = BooksReview::where('book_id', $bookid)->orderBy('add_time', 'desc')->paginate(10);
        foreach ($bookchangshupinglists as $bookchangshupinglist) {
            //得到发布长评论的会员资料
            $bookchangshupinglist['users'] = UsersReg::find($bookchangshupinglist->uid);
        }
        return $bookchangshupinglists;
    }
    
}